package com.chezai.client.adapter;

import android.support.annotation.LayoutRes;
import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chezai.client.R;
import com.chezai.client.bean.ClassRecord;
import com.chezai.client.global.Const;
import com.chezai.client.utils.DateUtil;

/**
 * Created by likunyang on 2017/9/13.
 */

public class CoachTrainRecordAdapter extends BaseQuickAdapter<ClassRecord, BaseViewHolder> {
    public CoachTrainRecordAdapter(@LayoutRes int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder holder, ClassRecord item) {
        if (item == null) return;
        holder.setText(R.id.tv_train_time, item.getCreateTime() + "\n" + DateUtil.timestampStr(item.getSignInTime(), "HH:mm") + "-" + DateUtil.timestampStr(item.getSignOutTime(), "HH:mm"))
                .setText(R.id.tv_train_part, item.getTrainPart() == Const.TrainPart.TWO ? "第二部分" : item.getTrainPart() == Const.TrainPart.THREE ? "第三部分" : "")
                .setText(R.id.tv_username, item.getUserInfo().getName())
                .setText(R.id.tv_train_subject, getTrainSubject(item.getTrainSubject()));
    }

    private String getTrainSubject(String trainSubject) {
        if (TextUtils.isEmpty(trainSubject)) {
            return "";
        }
        if (trainSubject.contains(",")) {
            String[] split = trainSubject.split(",");
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < split.length; i++) {
                sb.append(split[i]);
                if (i < split.length - 1) {
                    sb.append("\n");
                }
            }
            return sb.toString();
        }

        return trainSubject;
    }
}
